package com.wu.neihan.service;

import java.util.concurrent.LinkedBlockingQueue;

import org.apache.log4j.Logger;

public class QueueService {

	private static Logger logger = Logger.getLogger(QueueService.class);

	// 拥堵队列长度为10
	// 用户采集队列
	private static LinkedBlockingQueue<String> userQueue = new LinkedBlockingQueue<String>();
	// 段子采集队列
	private static LinkedBlockingQueue<String> postQueue = new LinkedBlockingQueue<String>();
	// 评论采集队列
	private static LinkedBlockingQueue<String> commentQueue = new LinkedBlockingQueue<String>();

	public static String getUserQueue() {
		queUeInfo();
		String id = "";
		try {
			id = userQueue.take();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return id;
	}

	public static String getPostQueue() {
		queUeInfo();
		String id = "";
		try {
			id = postQueue.take();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return id;
	}

	public static String getCommentQueue() {
		queUeInfo();
		String id = "";
		try {
			id = commentQueue.take();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return id;
	}

	public static void putUserQueue(String id) {
		try {
			userQueue.put(id);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void putpostQueue(String id) {
		try {
			postQueue.put(id);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void putcommentQueue(String id) {
		try {
			commentQueue.put(id);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static boolean checkSize(int size) {
		if (commentQueue.size() > size) {
			return true;
		}
		if (postQueue.size() > size) {
			return true;
		}
		if (userQueue.size() > size) {
			return true;
		}
		return false;
	}
	
	public static boolean checkCommentSize(int size) {
		if (commentQueue.size() > size) {
			return true;
		}
		return false;
	}
	public static boolean checkPostSize(int size) {
		if (postQueue.size() > size) {
			return true;
		}
		return false;
	}
	public static boolean checkUserSize(int size) {
		if (userQueue.size() > size) {
			return true;
		}
		return false;
	}
	
	public static void queUeInfo(){
		logger.info("<font color=#FF0000>用户队列：" + userQueue.size() + " 段子队列：" + postQueue.size() + " 评论队列：" + commentQueue.size()+"</font> ");
	}
}
